package com.sjl.db137.service.imp;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sjl.db137.service.RolemenuService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sjl.db137.mapper.RolemenuMapper;
import com.sjl.db137.entity.Rolemenu;

import java.util.List;

/**
 * @Author: zero domain
 * @CreateTime: 2024/12/24 11:49
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class RolemenuServiceImpl extends ServiceImpl<RolemenuMapper, Rolemenu> implements RolemenuService {

    @Override
    public boolean updateRoleMenuId(int roleid, List<Integer> listMenu) {
        //1、根据角色id删除这个角色的所有的菜单id
        UpdateWrapper<Rolemenu> rolemenuUpdateWrapper = new UpdateWrapper<>();
        rolemenuUpdateWrapper.eq("roleid",roleid);
        this.baseMapper.delete(rolemenuUpdateWrapper);
        //2、根据角色id增加对应的菜单
        for (Integer menu : listMenu) {
            Rolemenu rolemenu=new Rolemenu();
            rolemenu.setRoleid(roleid);
            rolemenu.setMenuid(menu);
            this.baseMapper.insert(rolemenu);
        }
        return true;
    }
}
